﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapFDECK(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        } 
        public void SaveFDECK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFDECK(dwData, 2);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFDECK(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertFDECK(dwLocal);
            }
            UpdateFDECK(dwLocal);
        }
        public void InsertFDECK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO FDECK(FDMANDANT, FDSA, FDAUFKRS, FDAUFLFD, FDAUFPOS, FDTYP, FDAFOLGE, FDSETPOS, FDART, FDVAR, FDFARBE, FDGROE, FDAUFM, FDVPEINH, FDZS, FDDAT, FDLO, FDLB, FDLP, FDAUFBKZ, FDMENGE, FDZUGET, FDFREIG, FDVERBR, FDRESERV, FDKOMMISS, FDSETANZ, FDERLKZ, FDDISPOKZ, FDABRKZ, FDFILLER)"
                + " VALUES (:FDMANDANT, :FDSA, :FDAUFKRS, :FDAUFLFD, :FDAUFPOS,:FDTYP, :FDAFOLGE, :FDSETPOS, 'FLT-G100            ', '  ', '          ', '14X3   ', '  ', '   ', '1 ', 20080920, '  ', '  ', '        ', ' ', 0, 0, 0, 0, 0, 0, 1, ' ', 'B', 'E', ' 0000                               ')";
            or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
            or1.Parameters.Add("FDSA", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
            or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
            or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
            or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
            or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
            or1.Parameters.Add("FDAFOLGE", OracleType.NVarChar).Value = dwData["FDAFOLGE"].ToString();
            or1.Parameters.Add("FDSETPOS", OracleType.NVarChar).Value = dwData["FDSETPOS"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteFDECK(string client, string krs, string lfd, string pos, string step = "", string setpos = "", int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();

            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FDECK "
                        + " WHERE FDMANDANT=:FDMANDANT   AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = lfd;
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = pos;
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM FDECK "
                        + " WHERE FDMANDANT=:FDMANDANT   AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD ";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = lfd;
                    break;
                case 3:
                    or1.CommandText = "DELETE FROM FDECK "
                        + " WHERE FDMANDANT=:FDMANDANT   AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD  AND FDAUFPOS=:FDAUFPOS AND FDAFOLGE=:FDAFOLGE AND FDSETPOS=:FDSETPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = lfd;
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = pos;
                    or1.Parameters.Add("FDAFOLGE", OracleType.NVarChar).Value = step;
                    or1.Parameters.Add("FDSETPOS", OracleType.NVarChar).Value = setpos;
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteFDECK(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();

            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FDECK "
                        + " WHERE FDMANDANT=:FDMANDANT   AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS AND FDART=:FDART";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"];
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"];
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"];
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"];
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"];
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM FDECK WHERE "
                   + "  FDMANDANT=:FDMANDANT  AND FDAUFKRS=:FDAUFKRS AND FDAUFLFD=:FDAUFLFD"
                        + " AND FDAUFPOS=:FDAUFPOS AND FDART=:FDART AND FDVAR=:FDVAR AND FDFARBE=:FDFARBE AND FDGROE=:FDGROE ";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();

                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    or1.Parameters.Add("FDVAR", OracleType.NVarChar).Value = dwData["FDVAR"].ToString();
                    or1.Parameters.Add("FDFARBE", OracleType.NVarChar).Value = dwData["FDFARBE"].ToString();
                    or1.Parameters.Add("FDGROE", OracleType.NVarChar).Value = dwData["FDGROE"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
     
        public void UpdateFDECK(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE FDECK SET "
                        + "FDMANDANT=:FDMANDANT,"
                        + "FDSA=:FDSA,"
                        + "FDAUFKRS=:FDAUFKRS,"
                        + "FDAUFLFD=:FDAUFLFD,"
                        + "FDAUFPOS=:FDAUFPOS,"
                        + "FDTYP=:FDTYP,"
                        + "FDAFOLGE=:FDAFOLGE,"
                        + "FDSETPOS=:FDSETPOS,"
                        + "FDART=:FDART,"
                        + "FDVAR=:FDVAR,"
                        + "FDFARBE=:FDFARBE,"
                        + "FDGROE=:FDGROE,"
                        + "FDAUFM=:FDAUFM,"
                        + "FDVPEINH=:FDVPEINH,"
                        + "FDZS=:FDZS,"
                        + "FDDAT=:FDDAT,"
                        + "FDLO=:FDLO,"
                        + "FDLB=:FDLB,"
                        + "FDLP=:FDLP,"
                        + "FDAUFBKZ=:FDAUFBKZ,"
                        + "FDMENGE=:FDMENGE,"
                        + "FDZUGET=:FDZUGET,"
                        + "FDFREIG=:FDFREIG,"
                        + "FDVERBR=:FDVERBR,"
                        + "FDRESERV=:FDRESERV,"
                        + "FDKOMMISS=:FDKOMMISS,"
                        + "FDSETANZ=:FDSETANZ,"
                        + "FDERLKZ=:FDERLKZ,"
                        + "FDDISPOKZ=:FDDISPOKZ,"
                        + "FDABRKZ=:FDABRKZ,"
                        + "FDFILLER=:FDFILLER "
                        + " WHERE  "
                        + "  FDMANDANT=:FDMANDANT AND FDSA=:FDSA AND FDAUFKRS=:FDAUFKRS AND FDAUFLFD=:FDAUFLFD"
                        + " AND FDAUFPOS=:FDAUFPOS AND FDTYP=:FDTYP AND FDAFOLGE=:FDAFOLGE AND FDSETPOS=:FDSETPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDSA", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    or1.Parameters.Add("FDAFOLGE", OracleType.NVarChar).Value = dwData["FDAFOLGE"].ToString();
                    or1.Parameters.Add("FDSETPOS", OracleType.NVarChar).Value = dwData["FDSETPOS"].ToString();
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    or1.Parameters.Add("FDVAR", OracleType.NVarChar).Value = dwData["FDVAR"].ToString();
                    or1.Parameters.Add("FDFARBE", OracleType.NVarChar).Value = dwData["FDFARBE"].ToString();
                    or1.Parameters.Add("FDGROE", OracleType.NVarChar).Value = dwData["FDGROE"].ToString();
                    or1.Parameters.Add("FDAUFM", OracleType.NVarChar).Value = dwData["FDAUFM"].ToString();
                    or1.Parameters.Add("FDVPEINH", OracleType.NVarChar).Value = dwData["FDVPEINH"].ToString();
                    or1.Parameters.Add("FDZS", OracleType.NVarChar).Value = dwData["FDZS"].ToString();
                    or1.Parameters.Add("FDDAT", OracleType.NVarChar).Value = dwData["FDDAT"].ToString();
                    or1.Parameters.Add("FDLO", OracleType.NVarChar).Value = dwData["FDLO"].ToString();
                    or1.Parameters.Add("FDLB", OracleType.NVarChar).Value = dwData["FDLB"].ToString();
                    or1.Parameters.Add("FDLP", OracleType.NVarChar).Value = dwData["FDLP"].ToString();
                    or1.Parameters.Add("FDAUFBKZ", OracleType.NVarChar).Value = dwData["FDAUFBKZ"].ToString();
                    or1.Parameters.Add("FDMENGE", OracleType.NVarChar).Value = dwData["FDMENGE"].ToString();
                    or1.Parameters.Add("FDZUGET", OracleType.NVarChar).Value = dwData["FDZUGET"].ToString();
                    or1.Parameters.Add("FDFREIG", OracleType.NVarChar).Value = dwData["FDFREIG"].ToString();
                    or1.Parameters.Add("FDVERBR", OracleType.NVarChar).Value = dwData["FDVERBR"].ToString();
                    or1.Parameters.Add("FDRESERV", OracleType.NVarChar).Value = dwData["FDRESERV"].ToString();
                    or1.Parameters.Add("FDKOMMISS", OracleType.NVarChar).Value = dwData["FDKOMMISS"].ToString();
                    or1.Parameters.Add("FDSETANZ", OracleType.NVarChar).Value = dwData["FDSETANZ"].ToString();
                    or1.Parameters.Add("FDERLKZ", OracleType.NVarChar).Value = dwData["FDERLKZ"].ToString();
                    or1.Parameters.Add("FDDISPOKZ", OracleType.NVarChar).Value = dwData["FDDISPOKZ"].ToString();
                    or1.Parameters.Add("FDABRKZ", OracleType.NVarChar).Value = dwData["FDABRKZ"].ToString();
                    or1.Parameters.Add("FDFILLER", OracleType.NVarChar).Value = dwData["FDFILLER"].ToString();
                    break;
                case 2:

                    or1.CommandText = "UPDATE FDECK SET "
                        + "FDMENGE=:FDMENGE"
                        + " WHERE  "
                        + "  FDMANDANT=:FDMANDANT  AND FDAUFKRS=:FDAUFKRS AND FDAUFLFD=:FDAUFLFD"
                        + " AND FDAUFPOS=:FDAUFPOS AND FDART=:FDART AND FDVAR=:FDVAR AND FDFARBE=:FDFARBE AND FDGROE=:FDGROE ";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();

                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    or1.Parameters.Add("FDVAR", OracleType.NVarChar).Value = dwData["FDVAR"].ToString();
                    or1.Parameters.Add("FDFARBE", OracleType.NVarChar).Value = dwData["FDFARBE"].ToString();
                    or1.Parameters.Add("FDGROE", OracleType.NVarChar).Value = dwData["FDGROE"].ToString();
                    or1.Parameters.Add("FDMENGE", OracleType.NVarChar).Value = dwData["FDMENGE"].ToString();

                    break;
                case 3:

                    or1.CommandText = "UPDATE FDECK SET "
                        + "FDKOMMISS=:FDKOMMISS"
                        + " WHERE  "
                        + "  FDMANDANT=:FDMANDANT  AND FDAUFKRS=:FDAUFKRS AND FDAUFLFD=:FDAUFLFD"
                        + " AND FDART=:FDART AND FDFARBE=:FDFARBE AND FDGROE=:FDGROE ";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();  
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString(); 
                    or1.Parameters.Add("FDFARBE", OracleType.NVarChar).Value = dwData["FDFARBE"].ToString();
                    or1.Parameters.Add("FDGROE", OracleType.NVarChar).Value = dwData["FDGROE"].ToString();
                    or1.Parameters.Add("FDKOMMISS", OracleType.NVarChar).Value = dwData["FDKOMMISS"].ToString();

                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QueryFDECK(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            string FSARTPRGR = "";
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FDECK WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM FDECK  "
                        + " WHERE FDMANDANT=:FDMANDANT AND FDSA=:FDSA AND FDTYP=:FDTYP AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDSA", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM FDECK  "
                        + " WHERE FDMANDANT=:FDMANDANT AND FDSA=:FDSA AND FDTYP=:FDTYP AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS"
                        + " AND FDAFOLGE=:FDAFOLGE  AND FDSETPOS=:FDSETPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDSA", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
                    or1.Parameters.Add("FDAFOLGE", OracleType.NVarChar).Value = dwData["FDAFOLGE"].ToString();
                    or1.Parameters.Add("FDSETPOS", OracleType.NVarChar).Value = dwData["FDSETPOS"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT DISTINCT ABKMANDANT, ABKAUFKRS,ABKAUFLFD,ABPART,FSABEZ  ,LSLIEFNA AS EXTPRODUCER,ABPLIEFNR,ABPANRKR,ABPALFDNR "
                    + " FROM FDECK F JOIN ABKOPF K ON F.FDAUFKRS=K.ABKAUFKRS AND  F.FDAUFLFD=K.ABKAUFLFD"
                    + " JOIN ABPOS P ON F.FDAUFKRS=P.ABPAUFKRS AND  F.FDAUFLFD=P.ABPAUFLFD AND  F.FDAUFPOS=P.ABPAUFPOS AND ABPGESSTA='SP'"
                    + " LEFT JOIN FSSTAMM M ON ABPART=FSART"
                    + " LEFT JOIN LIEFDAT M ON LSLIEFNR=ABPLIEFNR "
                    + " WHERE F.FDART=:FDART AND F.FDTYP=:FDTYP";
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT * FROM FDECK  "
                        + " WHERE FDMANDANT=:FDMANDANT AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    break;
                case 5:
                    or1.CommandText = "SELECT ABPAUFKRS,ABPAUFLFD,ABPAUFPOS,ABPART,ABPFARBE,ABPGROE,ABPSOLLMENGE7,FD.* FROM FDECK FD"
                    + "   JOIN ABPOS P ON FDAUFKRS=ABPAUFKRS AND FDAUFLFD=ABPAUFLFD AND FDAUFPOS=ABPAUFPOS  "
                        + " WHERE FDMANDANT=:FDMANDANT AND FDART=:FDART";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    break;
                case 6:
                    or1.CommandText = "SELECT FD.* FROM FDECK FD"
                        + " WHERE FDMANDANT=:FDMANDANT AND FDAUFKRS=:FDAUFKRS AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS"
                        + " AND FDART=:FDART AND FDVAR=:FDVAR AND FDFARBE=:FDFARBE AND FDGROE=:FDGROE";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    or1.Parameters.Add("FDVAR", OracleType.NVarChar).Value = dwData["FDVAR"].ToString();
                    or1.Parameters.Add("FDFARBE", OracleType.NVarChar).Value = dwData["FDFARBE"].ToString();
                    or1.Parameters.Add("FDGROE", OracleType.NVarChar).Value = dwData["FDGROE"].ToString();
                    break;
                case 7:
                    or1.CommandText = "SELECT FD.* FROM FDECK FD"
                        + " WHERE FDMANDANT=:FDMANDANT AND FDAUFKRS=:FDAUFKRS AND FDAUFLFD=:FDAUFLFD"
                        + " AND FDART=:FDART ";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    break;
                case 8:
                    string FDART = Left(dwData["FDFILLER"].ToString(), 20);
                    or1.CommandText = "SELECT ABPAUFKRS,ABPAUFLFD,ABPAUFPOS,ABPART,ABPFARBE,ABPGROE,ABPSOLLMENGE7,FD.* FROM FDECK FD"
                    + "   JOIN ABPOS P ON FDAUFKRS=ABPAUFKRS AND FDAUFLFD=ABPAUFLFD AND FDAUFPOS=ABPAUFPOS  "
                        + " WHERE FDMANDANT=:FDMANDANT AND ABPART=:ABPART AND FDART=:FDART";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("ABPART", OracleType.NVarChar).Value = dwData["FDART"].ToString();
                    or1.Parameters.Add("FDART", OracleType.NVarChar).Value = FDART;
                    break;
                case 9://分组 
                    FSARTPRGR = dwData["FDART"].ToString().Trim();
                    or1.CommandText = "SELECT DISTINCT A.*,Trim(C.FSFFBEZ) AS CDES,SP.LSLIEFNA AS SELLER, SP.LSNAME1 AS SELLERNAME "
                   + " FROM (SELECT DISTINCT FDMANDANT AS MANDANT,FDTYP AS DTYP,FDART AS ART,FDVAR AS VAR,FDFARBE AS COLOR ,"
                   + " Trim(MAX(S.FSABEZ))AS ARTDES, FDGROE AS ASIZE,ABACOLORREF AS CREF,"
                   + " SUM(ABARESMG) AS REQ,NVL(MAX(S.FSUEBM),'PCS') AS UM "
                   + " FROM INTEX.FDECK R "
                   + " JOIN INTEX.ICC_ABAUFM M ON R.FDAUFKRS=M.ABAVKAUFKRS AND R.FDAUFLFD=M.ABAVKAUFLFD AND R.FDAUFPOS=M.ABAVKAUFPOS AND ABAART=FDART AND  "
                   + " ABAVAR =FDVAR AND  ABAFARBE= FDFARBE  AND ABAGROE=FDGROE JOIN ABPOS P ON ABPSPGRD<='89' AND"
                   + " P.ABPAUFKRS=R.FDAUFKRS AND P.ABPAUFLFD=R.FDAUFLFD AND P.ABPAUFPOS=R.FDAUFPOS LEFT JOIN FSSTAMM S"
                   + " ON R.FDART=S.FSART AND R.FDVAR=S.FSVAR  "
                   + " WHERE  FDMANDANT=:FDMANDANT  AND FDTYP=:FDTYP AND FDSA=:FDSA AND FDZUGET=0 AND FDRESERV=0 AND M.ABAAUFTYP='N'"
                        //''+" AND FDART LIKE 'B140100115%' "
                   + " GROUP BY FDMANDANT,FDTYP,FDART,FDVAR,FDFARBE,FDGROE,ABACOLORREF"
                   + " ORDER BY FDMANDANT,FDTYP,FDART,FDVAR,FDFARBE,FDGROE,ABACOLORREF"
                   + " ) A   LEFT JOIN FSFARBEN C ON A.ART=FSFART AND A.VAR=FSFVAR AND A.COLOR=C.FSFFARBE"
                   + " LEFT JOIN FSEINK K ON A.ART=K.FEART AND A.VAR=K.FEVAR "
                   + " LEFT JOIN LIEFDAT SP ON FELIEFNR=SP.LSLIEFNR";

                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    or1.Parameters.Add("FDSA", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
                    break;
                case 10:
                    or1.CommandText = "SELECT FD.*,0 AS RATIO"
                        + " FROM FDECK FD"
                        + " WHERE FDMANDANT=:FDMANDANT AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    break;
                case 11:
                    or1.CommandText = "SELECT FD.*,0 AS RATIO"
                        + " FROM FDECK FD"
                        + " WHERE FDMANDANT=:FDMANDANT AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
                    break;
                case 12:
                    or1.CommandText = "SELECT * FROM FDECK  "
                        + " WHERE FDMANDANT=:FDMANDANT  AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD AND FDAUFPOS=:FDAUFPOS";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    or1.Parameters.Add("FDAUFPOS", OracleType.NVarChar).Value = dwData["FDAUFPOS"].ToString();
                    break;
                case 13:
                    or1.CommandText = "SELECT FD.*,0 AS RATIO"
                        + " FROM FDECK FD LEFT JOIN ABPOS ON FDMANDANT=ABPMANDANT AND FDAUFKRS=ABPAUFKRS  AND FDAUFLFD=ABPAUFLFD AND FDAUFPOS=ABPAUFPOS"
                        + " WHERE ABPMANDANT=:ABPMANDANT AND ABPAUFKRS=:ABPAUFKRS  AND ABPAUFLFD=:ABPAUFLFD AND ABPART=:ABPART AND ABPFARBE=:ABPFARBE";
                    or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwData["ABPMANDANT"].ToString();
                    or1.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwData["ABPAUFKRS"].ToString();
                    or1.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwData["ABPAUFLFD"].ToString();
                    or1.Parameters.Add("ABPART", OracleType.NVarChar).Value = dwData["ABPART"].ToString();
                    or1.Parameters.Add("ABPFARBE", OracleType.NVarChar).Value = dwData["ABPFARBE"].ToString();
                    break;
                case 16:
                    or1.CommandText = "SELECT DISTINCT FDART AS WDART FROM EKPOS EK JOIN FDECK ON "
                        + " EKPSA<>'AJ'  AND utl_raw.cast_to_varchar2(EKPART)=FDART  "
                        + " AND utl_raw.cast_to_varchar2(EKPFARBE)=FDFARBE  AND EKPGROE=FDGROE AND EKPBEKZ=:EKPBEKZ"
                        + " JOIN ABPOS ON ABPAUFKRS=FDAUFKRS AND ABPAUFLFD=FDAUFLFD AND ABPAUFPOS=FDAUFPOS"
                        + " JOIN FSSTAMM M ON FSART=ABPART"
                        + " JOIN FSSTUELI ON ABPART=FSSART AND FDART=FSSMART AND "
                        + " M.FSARTPRGR IN  (" + dwData["FDART"].ToString().Trim() + ")"
                        + " WHERE FDMANDANT=:FDMANDANT AND FDTYP=:FDTYP";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    or1.Parameters.Add("EKPBEKZ", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
                    break;
                case 17:
                    or1.CommandText = "SELECT DISTINCT FSART AS WDART FROM EKPOS EK JOIN FSSTAMM M ON "
                        + " EKPSA<>'AJ'  AND utl_raw.cast_to_varchar2(EKPART)=FSART AND EKPBEKZ=:EKPBEKZ "
                        + " M.FSARTPRGR IN  (" + dwData["FDART"].ToString().Trim() + ")"
                        + " WHERE FSMANDANT=:FDMANDANT ";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("EKPBEKZ", OracleType.NVarChar).Value = dwData["WDSA"].ToString();
                    break;
                case 19:
                    or1.CommandText = "SELECT FDAUFKRS,FDAUFLFD,FDAUFPOS, FDSETPOS,FDART,FDFARBE,FDGROE,"
                    +"ABPFARBE,ABARESMG,ABAQTYRESERVE,EKPAUFKRS,EKPAUFLFD,EKPAUFPOS,EKPME1,EKPME3 FROM FDECK"
                        + " LEFT JOIN ICC_ABAUFM ON FDAUFKRS=ABAVKAUFKRS AND FDAUFLFD=ABAVKAUFLFD AND FDAUFPOS=ABAVKAUFPOS"
                        + " AND FDART=ABAART AND FDFARBE=ABAFARBE AND FDGROE=ABAGROE"
                        + " LEFT JOIN EKPOS ON EKPAUFKRS=ABAAUFKRS AND EKPAUFLFD=ABAAUFLFD AND EKPAUFPOS=ABAAUFPOS AND EKPSA='PO'"
                        + " WHERE FDMANDANT=:FDMANDANT AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    break;
                case 91://分组 
                    string art = dwData["FDART"].ToString().Trim();
                    or1.CommandText = "SELECT DISTINCT A.*,Trim(C.FSFFBEZ) AS CDES,NVL(SP.LSLIEFNA,'YCA       ') AS SELLER, NVL(SP.LSNAME1,'YCA                                     ') AS SELLERNAME "
                    + " FROM (SELECT DISTINCT FDMANDANT AS MANDANT,FDTYP AS DTYP,FDART AS ART,FDVAR AS VAR,FDFARBE AS COLOR ,"
                    + " Trim(MAX(S.FSABEZ))AS ARTDES, FDGROE AS ASIZE,ABACOLORREF AS CREF,M.ABPART,MAX(M.FSABEZ) AS FSABEZ,"
                    + " SUM(ABARESMG) AS REQ,NVL(MAX(S.FSUEBM),'PCS') AS UM "
                    + " FROM INTEX.FDECK R "
                    + " JOIN INTEX.ICC_ABAUFM M ON R.FDAUFKRS=M.ABAVKAUFKRS AND R.FDAUFLFD=M.ABAVKAUFLFD AND R.FDAUFPOS=M.ABAVKAUFPOS AND ABAART=FDART AND  "
                    + " ABAVAR =FDVAR AND  ABAFARBE= FDFARBE  AND ABAGROE=FDGROE JOIN ABPOS P ON ABPSPGRD<='89' AND"
                    + " P.ABPAUFKRS=R.FDAUFKRS AND P.ABPAUFLFD=R.FDAUFLFD AND P.ABPAUFPOS=R.FDAUFPOS LEFT JOIN FSSTAMM S"
                    + " ON R.FDART=S.FSART AND R.FDVAR=S.FSVAR  "
                    + " WHERE  ABAART LIKE '%" + art.Trim() + "%' AND FDMANDANT=:FDMANDANT  AND FDTYP=:FDTYP AND FDSA=:FDSA AND FDZUGET=0 AND FDRESERV=0 AND M.ABAAUFTYP='N'"
                        //''+" AND FDART LIKE 'B140100115%' "
                    + " GROUP BY FDMANDANT,FDTYP,FDART,FDVAR,FDFARBE,FDGROE,ABACOLORREF,M.ABPART"
                    + " ORDER BY FDMANDANT,FDTYP,FDART,FDVAR,FDFARBE,FDGROE,ABACOLORREF"
                    + " ) A   LEFT JOIN FSFARBEN C ON A.ART=FSFART AND A.VAR=FSFVAR AND A.COLOR=C.FSFFARBE"
                    + " LEFT JOIN FSEINK K ON A.ART=K.FEART AND A.VAR=K.FEVAR "
                    + " LEFT JOIN LIEFDAT SP ON FELIEFNR=SP.LSLIEFNR";

                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDTYP", OracleType.NVarChar).Value = dwData["FDTYP"].ToString();
                    or1.Parameters.Add("FDSA", OracleType.NVarChar).Value = dwData["FDSA"].ToString();
                    break; 
                case 99:
                    or1.CommandText = "SELECT 	FDMANDANT,FDTYP,FDAUFKRS,FDAUFLFD,FDAUFPOS,SUBSTR(FDSETPOS,2,2) AS FDUPOS,FDART,FDVAR,FDFARBE"
                    + ",FSABEZ AS ARTDES,FSFABEZ AS CDES,FDGROE,FDMENGE,FDZUGET,FDFREIG,FDVERBR,	FDRESERV,0 AS RATIO"
                        + " FROM FDECK  "
                        + " LEFT JOIN FSSTAMM ON FSART=FDART AND FSVAR=FDVAR"
                        + " LEFT JOIN FSFARBEN ON FSFART=FDART AND FSFVAR=FDVAR AND FSFFARBE=FDFARBE  "
                        + " WHERE FDMANDANT=:FDMANDANT AND FDSA='V' AND FDTYP='B' AND FDAUFKRS=:FDAUFKRS  AND FDAUFLFD=:FDAUFLFD"
                        + " ORDER BY FDART,FDVAR,FDFARBE,FDGROE";
                    or1.Parameters.Add("FDMANDANT", OracleType.NVarChar).Value = dwData["FDMANDANT"].ToString();
                    or1.Parameters.Add("FDAUFKRS", OracleType.NVarChar).Value = dwData["FDAUFKRS"].ToString();
                    or1.Parameters.Add("FDAUFLFD", OracleType.NVarChar).Value = dwData["FDAUFLFD"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FDECK";
            Return = Result;
            return Return;
        }
    }
}
